/*
 * @Author: Sam
 * @Date: 2020-10-12 15:23:33
 * @LastEditTime: 2021-03-03 15:24:02
 * @LastEditors: Sam
 * @Description:
 * @FilePath: \tofba-client\src\store\modules\createWaybill.js
 * @可以输入预定的版权声明、个性签名、空行等
 * 
 * 后期再开发  框架不允许
 */
const state = {

  japanLine: [16, 17, 99, 115, 229, 227, 226, 136, 115, 88, 84, 34, 33],// 日本专线
  createTpye: '',
  channelFormLeft: {},
  channelFormRight: {},
  selectedImporterInfo: {},
  invoiceInfo: {},
  packingInfo: [],

}

const mutations = {
  CHANGE_CHANNEL_FORM_LEFT: (state, view) => {
    // eslint-disable-next-line no-prototype-builtins
    if (JSON.stringify(view) === '{}') {
      state.channelFormLeft = {}
    } else {
      state.channelFormLeft = Object.assign({}, state.channelFormLeft, view)
    }
    // console.log('state.channelFormLeft', state.channelFormLeft)
  },
  CHANGE_CHANNEL_FORM_RIGHT: (state, view) => {
    // eslint-disable-next-line no-prototype-builtins
    if (JSON.stringify(view) === '{}') {
      state.channelFormRight = {}
    } else {
      state.channelFormRight = Object.assign({}, state.channelFormRight, view)
    }

    console.log('state.channelFormRight :>> ', state.channelFormRight);
  },
  SELECTED_IMPORTER_INFO: (state, view) => {
    // eslint-disable-next-line no-prototype-builtins
    if (JSON.stringify(view) === '{}') {
      state.selectedImporterInfo = {}
    } else {
      state.selectedImporterInfo = Object.assign({}, state.selectedImporterInfo, view)
    }
  },
  CHANGE_INVOICE_INFO: (state, view) => {
    // eslint-disable-next-line no-prototype-builtins
    if (JSON.stringify(view) === '{}') {
      state.invoiceInfo = {}
    } else {
      state.invoiceInfo = Object.assign({}, state.invoiceInfo, view)
    }
    console.log('state.invoiceInfo', state.invoiceInfo)
  },
  CHANGE_PACKING_INFO: (state, view) => {
    // eslint-disable-next-line no-prototype-builtins
    state.packingInfo = view
    console.log('state.packingInfo', state.packingInfo)
  },

  SET_CREATETYPE: (state, view) => {
    state.createTpye = view
  }
}

const actions = {
  changeChannelFormLeft ({ commit }, data) {
    commit('CHANGE_CHANNEL_FORM_LEFT', data)
  },
  changeChannelFormRight ({ commit }, data) {
    commit('CHANGE_CHANNEL_FORM_RIGHT', data)
  },
  selectedImporterInfo ({ commit }, data) {
    commit('SELECTED_IMPORTER_INFO', data)
  },
  changeInvoiceInfo ({ commit }, data) {
    commit('CHANGE_INVOICE_INFO', data)
  },
  changePackingInfo ({ commit }, data) {
    commit('CHANGE_PACKING_INFO', data)
  },
  setCreateTpye ({ commit }, data) {
    commit('SET_CREATETYPE', data)
  }

}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
